package com.lingjtx.common.core.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;
import java.util.Map;

public class XmlUtil {

    private static final Logger log = LoggerFactory.getLogger(XmlUtil.class);

    private static Map<String, String> map;

    static {
        try {
            //创建一个解析器工厂对象
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser saxParser = spf.newSAXParser();
            //解析文件
            InputStream in = XmlUtil.class.getClassLoader().getResourceAsStream("InfluxDBDao.xml");
            XmlHandle handle = new XmlHandle();
            saxParser.parse(in, handle);
            map = handle.getMap();
        } catch (Exception e) {
            log.error("XmlUtil Parser 异常：{}", e.getMessage());
        }
    }

    public static String getContentById(String id) {
        if (map != null) {
            return map.get(id);
        }
        return null;
    }

    public static Map getMap() {
        return map;
    }
}
